﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TFSUtils.ViewModel;
using TFSUtils.Model;
using TFSUtils.Test.Mock;
using System.Linq;
using System.Collections.ObjectModel;
using GalaSoft.MvvmLight.Views;

namespace TFSUtils.Test
{
    [TestClass]
    public class MainViewModelTest
    {
        [TestMethod]
        public void FindOrphanedWorkspaces()
        {
            IDataService ds = new Mock.MockDataService();
            INavigationService ns = new Mock.MockNavigationService();
            MockMainViewModel mvm = new MockMainViewModel(ds, ns);

            Assert.IsTrue(mvm.FindOrphanedWorkspaceCommand.CanExecute(null));
            mvm.FindOrphanedWorkspaceCommand.Execute(null);            
        }

        [TestMethod]
        public void CleanWorkspaces()
        {
            IDataService ds = new Mock.MockDataService();
            INavigationService ns = new Mock.MockNavigationService();
            MockMainViewModel mvm = new MockMainViewModel(ds, ns);

            mvm.CleanWorkspaceCommand.Execute(null);

        }

        [TestMethod]
        public void CheckHistory()
        {
            IDataService ds = new Mock.MockDataService();
            INavigationService ns = new Mock.MockNavigationService();
            MockMainViewModel mvm = new MockMainViewModel(ds, ns);

            mvm.ShowCheckoutStatusCommand.Execute(null);

        }

        [TestMethod]
        public void AddToStatusText()
        {
            IDataService ds = new Mock.MockDataService();
            INavigationService ns = new Mock.MockNavigationService();
            MockMainViewModel mvm = new MockMainViewModel(ds, ns);

            mvm.AddToStatus("test", StatusType.Error);

            Assert.AreEqual(mvm.Status.Count, 1);
            Assert.AreEqual(mvm.Status.First().Description, "test");
        }

        [TestMethod]
        public void AddToMultipleStatusText()
        {
            IDataService ds = new Mock.MockDataService();
            INavigationService ns = new Mock.MockNavigationService();
            MockMainViewModel mvm = new MockMainViewModel(ds, ns);            

            mvm.AddToStatus("test", StatusType.Error);
            mvm.AddToStatus("test2", StatusType.Error);
            mvm.AddToStatus("test3", StatusType.Error);
            mvm.AddToStatus("test4", StatusType.Error);

            Assert.AreEqual(mvm.Status.Count, 4);
            Assert.AreEqual(mvm.Status.First().Description, "test");
            Assert.AreEqual(mvm.Status.Last().Description, "test4");
        }

        [TestMethod]
        public void AddToStatusList()
        {
            IDataService ds = new Mock.MockDataService();
            INavigationService ns = new Mock.MockNavigationService();
            MockMainViewModel mvm = new MockMainViewModel(ds, ns);

            ObservableCollection<string> status = new ObservableCollection<string>();
            status.Add("test");
            status.Add("test2");
            mvm.AddToStatus(status, StatusType.Error);

            Assert.AreEqual(mvm.Status.Count, 2);
            Assert.AreEqual(mvm.Status.First().Description, "test");
            Assert.AreEqual(mvm.Status.Last().Description, "test2");
        }

    }
}
